import { createRouter, createWebHistory } from 'vue-router';
import type {RouteRecordRaw} from 'vue-router';
import chapter1 from './chapter1';
import chapter2 from './chapter2';
import chapter3 from './chapter3';
import car from './car';

const routes: RouteRecordRaw[] = [
	...chapter1,
	...chapter2,
	...chapter3,
	...car
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

//前置守卫
router.beforeEach((to, from, next) => {
	document.title = 'threejs+vite+vue3 ' + to.meta.title as string;
	
	let gui = window.gui;
	
	if(gui){
		//存在 gui 实例
		gui.destroy();
		window.gui = null;
	}
	
	next();
});

export default router;